import json

from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.ms.v20180408.ms_client import *
from tencentcloud.ms.v20180408 import ms_client, models
from tencentcloud.common.credential import Credential
import config

config = config.Config()


class Client:
    def __init__(self):
        cred = Credential(config.get_legu_info()["ak"], config.get_legu_info()["sk"])
        # 实例化一个http选项，可选的，没有特殊需求可以跳过
        httpProfile = HttpProfile()
        httpProfile.endpoint = "ms.tencentcloudapi.com"
        models.CreateBindInstanceResponse()
        # 实例化一个client选项，可选的，没有特殊需求可以跳过
        clientProfile = ClientProfile()
        clientProfile.httpProfile = httpProfile
        # 实例化要请求产品的client对象,clientProfile是可选的
        self.client = ms_client.MsClient(cred, "", clientProfile)

    def pin_up(self, params: dict) -> dict:
        req = models.CreateShieldInstanceRequest()
        req.from_json_string(json.dumps(params))
        resp = self.client.CreateShieldInstance(req)
        return json.loads(resp.to_json_string())

    def find_result(self, params: dict) -> dict:
        req = models.DescribeShieldResultRequest()
        req.from_json_string(json.dumps(params))
        resp = self.client.DescribeShieldResult(req)
        return json.loads(resp.to_json_string())
